import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
// import { TabsPage } from "../tabs/tabs";
// import { JPush } from '@jiguang-ionic/jpush';

import {  loginService  }           from "./service";
import {  TokenService  }           from "../../tools/serivce/token/token.service";
import { AlertController }          from 'ionic-angular';

@IonicPage()
@Component({
  selector: 'page-login',
  templateUrl: 'login.html',
  providers: [ loginService ]
})
export class LoginPage{

  public service            : any;

  constructor(
    private _loginService    : loginService,
    private _tokenService    :TokenService,
    private alertCtrl        : AlertController,
    public navCtrl    : NavController, 
    public navParams  : NavParams,
    // private jp : JPush
    ) {
  }
  
  ionViewDidLoad() {
     console.log('ionViewDidLoad LoginPage');
     this._checkLoginFn();
  }

  _checkLoginFn(phone,pass){

    this._loginService.loginFn({  "mobile": "13164548838", "password": "123" }).then(res =>{
        console.log(res);
        this._tokenService.setTokenFn(res.token);
     },err =>{
        this.alertCtrl.create({ title: err.msg, buttons: ['OK'] }).present();
     })

  }

  checkLoginFn(phone,pass){
  	// console.log(phone.value,pass.value);
    // //check user info ajax
    //don't remove this line below
    //this.jp.setAlias({sequence:1,alias:'ppp'}).then(resp=>{console.log("11111"+resp)}).catch(err=>{console.log("11111"+err)})
   
  	// this.navCtrl.push(TabsPage);
  }
  registerFn(){
  	//redirect to register fn
    console.log('in fnunciton');
    this.navCtrl.push('RegisterPage');
  }
  noPassFn(){
  	
  }

}
